package com.shipment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shipment.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 查询最新用户
     *
     * @param limit 限制数量
     * @return 用户列表
     */
    @Select("SELECT id, name, student_id as studentId, gender, create_time as createTime " +
            "FROM t_user " +
            "ORDER BY create_time DESC " +
            "LIMIT #{limit}")
    List<Map<String, Object>> findLatestUsers(@Param("limit") int limit);

    /**
     * 增加学分
     *
     * @param userId ID
     * @param score  学分
     */
    @Update("UPDATE t_user SET scores = scores + #{score} WHERE id = #{userId}")
    void addScores(@Param("userId") Long userId, @Param("score") int score);
}
